﻿using Framework.Common;
using Framework.EncryptionDecryptionService.Achieve;
using Framework.EncryptionDecryptionService.Attributes;
using Framework.EncryptionDecryptionService.Enums;
using Framework.EncryptionDecryptionService.Inteface;
using Framework.RequestEntitys.Models;
using Microsoft.AspNetCore.Mvc;

namespace Bright.NetCore.Api.Controllers
{
    [ApiController]
    [Route("api/Test/[action]")]
    public class TestController : Controller
    {
        private IEncryptionDecryptionService service;
        public TestController(IEncryptionDecryptionService service) 
        {
            this.service = service;
        }

        [NonEncrypted(EncryptionType.Full)]
        public object ResponseData(List<TestModel> data)
        {
            return data;
        }

        [NonEncrypted]
        public object RsaEncryption(TestModel model)
        {
            return new { msg = service.EncryptionService(EncryptionAlgorithm.RSA).Encrypt(model),secretKey = service.EncryptionService(EncryptionAlgorithm.RSA).GetSecretKey } ;
        }

        [NonEncrypted]
        public object AesEncryption(TestModel model)
        {
            return new { msg = service.EncryptionService(EncryptionAlgorithm.AES).Encrypt(model), secretKey = service.EncryptionService(EncryptionAlgorithm.AES).GetSecretKey };
        }

        [NonEncrypted]
        public object RsaDecryption(TestModel model)
        {
            return new { msg = service.DecryptionService(EncryptionAlgorithm.RSA).Decrypt<TestModel>(model.Name), secretKey = service.DecryptionService(EncryptionAlgorithm.RSA).GetSecretKey };
        }

        [NonEncrypted]
        public object AesDecryption(TestModel model)
        {
            return new { msg = service.DecryptionService(EncryptionAlgorithm.AES).Decrypt<TestModel>(model.Name), secretKey = service.DecryptionService(EncryptionAlgorithm.AES).GetSecretKey };
        }

        [NonEncrypted]
        public object RsaEncryptionScope(TestModel model)
        {
            EncryptionServiceRsa serviceAes = new EncryptionServiceRsa();
            return new { msg = serviceAes.Encrypt(model), secretKey = serviceAes.GetSecretKey };
        }

        [NonEncrypted]
        public object AesEncryptionScope(TestModel model)
        {
            EncryptionServiceAes serviceAes = new EncryptionServiceAes();
            return new { msg = serviceAes.Encrypt(model), secretKey = serviceAes.GetSecretKey };
        }

        [NonEncrypted]
        public object RsaDecryptionScope(TestModel model)
        {
            DecryptionServiceRsa serviceAes = new DecryptionServiceRsa();
            return new { msg = serviceAes.Decrypt(model.Name), secretKey = serviceAes.GetSecretKey };
        }

        [NonEncrypted]
        public object AesDecryptionScope(TestModel model)
        {
            DecryptionServiceAes serviceAes = new DecryptionServiceAes();
            return new { msg = serviceAes.Decrypt(model.Name), secretKey = serviceAes.GetSecretKey };
        }
    }
}
